package com.gs.api.projects.bzapplets.web;

import com.github.pagehelper.PageInfo;
import com.gs.api.projects.bzapplets.service.BzConfigService;
import com.gs.api.projects.bzapplets.service.BzFavoriteService;
import com.gs.api.projects.bzapplets.vo.BzWallpaperVo;
import com.gs.api.core.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author guoyunfei on 2021/7/11 15:45
 * @className BzFavoriteController
 * @description TODO
 * @Version 1.0
 */
@Api(tags = "我的收藏，点赞，浏览")
@RestController
@RequestMapping("{appid}/favorite")
public class BzFavoriteController {

    @Autowired
    private BzFavoriteService bzFavoriteService;

    @Autowired
    private BzConfigService bzConfigService;

    @ApiOperation(value = "我的收藏，点赞，浏览", notes="我的收藏，点赞，浏览")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码，默认1", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "条数，默认12", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "openid", value = "用户微信openid", required = true, dataType = "String"),
            @ApiImplicitParam(name = "appid", value = "小程序appid", required = true, dataType = "String"),
    })
    @GetMapping("/getMyData")
    private Result getMyData(BzWallpaperVo wallpaper, Integer pageNum, Integer pageSize, @PathVariable String appid){
        wallpaper.setAppid(appid);

        if(null == pageNum){
            pageNum = 1;
        }
        if(null == pageSize){
            pageSize = 12;
        }
        PageInfo<BzWallpaperVo> pageInfo = bzFavoriteService.getMyData(wallpaper, pageNum, pageSize);
        List<BzWallpaperVo> list = pageInfo.getList();

        int size = list.size();

        for (int i = 0; i < size; i++) {
            list.get(i).setThumbnail(list.get(i).getOssResourcesurl() + list.get(i).getThumbnail());
        }
        pageInfo.setList(list);
        return Result.success(pageInfo);
    }

    @ApiOperation(value = "我的收藏，点赞，浏览-新增采集数据", notes="我的收藏，点赞，浏览-新增采集数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码，默认1", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "条数，默认12", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "openid", value = "用户微信openid", required = true, dataType = "String"),
            @ApiImplicitParam(name = "appid", value = "小程序appid", required = true, dataType = "String"),
    })
    @GetMapping("/getMyDataNew")
    private Result getMyDataNew(BzWallpaperVo wallpaper, Integer pageNum, Integer pageSize, @PathVariable String appid){
        wallpaper.setAppid(appid);
        if(null == pageNum){
            pageNum = 1;
        }
        if(null == pageSize){
            pageSize = 12;
        }
        PageInfo<BzWallpaperVo> pageInfo = bzFavoriteService.getMyDataNew(wallpaper, pageNum, pageSize);
        List<BzWallpaperVo> list = pageInfo.getList();
        pageInfo.setList(list);
        return Result.success(pageInfo);
    }

}
